﻿// ## 2023/09/26 # 氕氘氚 # 重构 ##
// ## 2023/04/25 # 江东新风 # 特技转特效 ##
// ## 2021/10/01 # 江东新风 # namespace的韩文改成英文 ##
// ## 2020/12/22 # 江东新风 # 山战背水特技 ##
// ## 2020/08/16 # 江东新风 # has_skill函数替換 ##
// ## 2020/07/26 ##
namespace TERRAIN_CLIFFROAD_DAMAGE
{
	//---------------------------------------------------------------------------------------
	const int 栈道基础伤害 = 200;
	const int 难所行军栈道伤害倍率 = 20;
	const int 山地行军士气减少 = 5;
	//---------------------------------------------------------------------------------------

	class Main
	{
		Main()
		{
			pk::set_func(218, pk::func218_t(callback));
		}

		int callback(pk::unit @unit, const pk::point& in pos)
		{

			int damage = 栈道基础伤害;

			if (ch::has_skill(unit, 特技_山战) and pk::get_hex(pos).terrain == 地形_山)
				return 0;
			if (ch::has_skill(unit, 特技_背水) and pk::get_hex(pos).terrain == 地形_岸)
				return 0;

			if (!ch::has_skill(unit, 特技_山战) and pk::get_hex(pos).terrain == 地形_山)
			{
				int distance = 1;

				int energy_diff = 山地行军士气减少;
				int troops_diff = damage + int(unit.troops * 0.03);

				if (ch::has_skill(unit, 特技_踏破))
				{
					energy_diff = energy_diff * pk::core::skill_constant_value(特技_踏破) / 100;
					troops_diff = troops_diff * pk::core::skill_constant_value(特技_踏破) / 100;
				}

				if (unit.troops < 1000)
					energy_diff *= 2;

				if (unit.energy - energy_diff > 0)
				{	
					//在AI还没有解决路径的时候,先减半影响
					if (!unit.is_player() and pk::rand(3) < 2)
						pk::add_energy(unit, -energy_diff, true);
					return 0;
				}
				else
				{
					return troops_diff;
				}
			}

			if (ch::has_skill(unit, 特技_踏破))
				damage = damage * pk::core::skill_constant_value(特技_踏破) / 100;
			if (unit.has_tech(技巧_难所行军))
				damage = damage * 难所行军栈道伤害倍率 / 100;
			if (!unit.is_player()) damage /= 3;

			damage = int(damage * ch::randfloat(0.8, 1.2));
			return damage;
		}
	}

	Main main;
}